<template>
	<div class="bgBox">
		<div class="cardBox">
			<div class="container">
				<div class="card">
					<h3>{{zhuti}}</h3>
				</div>
				<div class="yyBox">
					<div class="btns" v-if="!showSuit">
						<div class="btn" @click="showSuit = true">参与排序</div>
					</div>
					<image v-if="showSuit && jsimg && sortIndex > 0" class="jsimg" :src="jsimg" mode="widthFix" @click="showImg(jsimg)"></image>
					<small v-if="showSuit">
						<template v-if="sortIndex > 0">
							{{username}}同学，您的位置{{sortIndex}}号
						</template>
						<template v-else>
							没有您的上课信息
						</template>
					</small>
				</div>
			</div>
		</div>
		
		<u-toast ref="uToast"></u-toast>
	</div>
</template>

<script>
const db = wx.cloud.database();
export default {
	name: 'headcomd',
	data() {
		return {
			wyz: '',
			zhuti:"",
			sortIndex: -1,
			list:[],
			showSuit: false,
			username:"",
			jsimg:""
		};
	},
	onShareAppMessage(options) {
		let that = this
		let shareObj = {
		    title: that.zhuti,
		    path: 'pages/huodong/paizuo/paixu_join?wyz=' + that.wyz,
		    imageUrl: ''   
		};
		return shareObj
	},
	onShareTimeline(res) {
		let that = this;
		return {
			title: that.zhuti,
			query: "wyz=" + that.wyz
		};
	},
	onLoad(options) {
		if (!options) {
			this.infoScene = 'default';
		} else {
			this.wyz = options.hdid;
			this.getPageInfo();
		}
	},
	computed: {},
	mounted() {
		
		
	},
	watch: {},
	created() {
		let that = this;
	},
	computed:{
		userphone() {
			return this.$store.getters.userphone ? this.$store.getters.userphone : '';
		},
	},
	methods: {
		getPageInfo() {
			let that = this;
			console.log(that.wyz)
			db.collection('paixu_lists').doc(that.wyz).get({
				success: function(res) {
					console.log(res)
					that.zhuti = res.data.zhuti;
					that.list = res.data.list
					that.jsimg = res.data.jsimg
					that.filterMy()
				}
			});
		},
		filterMy(){
			let that = this
			if(that.userphone){
				that.list.map((item,index) => {
					if(item['电话'] == that.userphone){
						that.username = item['姓名']
						that.sortIndex = index + 1
						
					}
				})
			}
		},
		showImg(img){
			wx.previewImage({
				urls: [img], //需要预览的图片http链接列表，注意是数组
				current: '', // 当前显示图片的http链接，默认是第一个
				success: function(res) {},
				fail: function(res) {},
				complete: function(res) {}
			});
		}
	}
};
</script>

<style>
@import url(./index.css);
</style>
